package com.swan.controllers;

import java.util.List;

import com.swan.beans.StudentClassReg;
import com.swan.models.ClassDao;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;

/**
 * StudentClassRegController
 * 
 * @author xyh
 * @param <T>
 * @date 20230426
 *
 */

public class StudentClassRegController {

	@FXML
	private TableView<StudentClassReg> TableView;

	// Table view fields
	@FXML
	private TableColumn<StudentClassReg, String> UserNameTableColumn;

	@FXML
	private TableColumn<StudentClassReg, String> SeasonNameTableColumn;

	@FXML
	private TableColumn<StudentClassReg, String> ClassTitleTableColumn;

	private final ObservableList<StudentClassReg> data = FXCollections.observableArrayList();

	private ClassDao dao = new ClassDao();

	@FXML
	private void initialize() {
		// table view
		// set column value
		UserNameTableColumn.setCellValueFactory(new PropertyValueFactory<StudentClassReg, String>("userName"));
		SeasonNameTableColumn.setCellValueFactory(new PropertyValueFactory<StudentClassReg, String>("seasonName"));
		ClassTitleTableColumn.setCellValueFactory(new PropertyValueFactory<StudentClassReg, String>("classTitle"));

		// set table view
		List<StudentClassReg> list = dao.listStudentClassReg();
		System.out.println("list class register success!");
		data.addAll(list);

		TableView.setItems(data);
		TableView.setEditable(true);

	}

}
